#include "chatserver.hpp"
#include "chatservice.hpp"
#include <iostream>
#include <signal.h>
using namespace std;

// 捕获函数-调用服务器终止重置用户信息
void resetHandler(int)
{
    ChatService::getInstance()->reset();
    exit(0);
}

int main(int argc, char **argv)
{
    if (argc < 3)
    {
        cerr << "Usage: ./ChatServer 127.0.0.1 6666/9999" << endl;
        exit(-1);
    }
    // 捕捉服务器程序中断信号
    signal(SIGINT, resetHandler);
    EventLoop loop;
    InetAddress listenAddr(argv[1], atoi(argv[2]));
    ChatServer server(&loop, listenAddr, "ChatServer");
    server.start();
    loop.loop();
    return 0;
}